<!DOCTYPE html>
<html xmlns:layout="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
	layout:decorate="~{common/layoutAdmin}">

<head>
	<meta charset="UTF-8">
	<title>帖子</title>
</head>

<body>
	<div layout:fragment="fragment_body">
		<el-row :gutter="20">
			<el-col :span="14">
				<!--<el-button type="primary" @click="openRacePost(null)">添 加</el-button>-->
				<el-table :data="racePosts" border highlight-current-row style="width: 100%">
					<!-- -->
					<el-table-column prop="postUserId" label="发布人">
						<template slot-scope="scope">
						{{scope.row.postUser?.accountName}}
						</template>
					</el-table-column>
					<el-table-column prop="postText" label="内容"></el-table-column>
					<el-table-column prop="postTime" label="发布时间"></el-table-column>
					<el-table-column label="操作" width="160px">
						<template slot-scope="scope">
							<!--<el-button @click="openRacePost(scope.row)" type="text" size="small">修 改</el-button>-->
							<el-button @click="viewRacePost(scope.row)" type="text" size="small">查看评论</el-button>
							<el-popconfirm title="是否删除？" @confirm="delRacePost(scope.row.postId)">
								<el-button slot="reference" type="text" size="small">删 除</el-button>
							</el-popconfirm>
						</template>
					</el-table-column>
				</el-table>
			</el-col>
			<el-col :span="10">
				<el-table :data="raceComments" border highlight-current-row style="width: 100%">
					<!-- -->
					<!--<el-table-column prop="commentParentId" label="所在评论">
						<template slot-scope="scope">
						{{scope.row.infoPublish?.accountName}}
						</template>
					</el-table-column>-->
					<!--<el-table-column prop="commentPostId" label="所在帖子">
						<template slot-scope="scope">
						{{scope.row.post?.postText}}
						</template>
					</el-table-column>-->
					<el-table-column prop="commentUserId" label="评论人">
						<template slot-scope="scope">
						{{scope.row.user?.accountName}}
						</template>
					</el-table-column>
					<el-table-column prop="commentText" label="内容">
						<template slot-scope="scope">
						{{scope.row.commentText}}
						<br>{{scope.row.commentTime}}
						</template>
					</el-table-column>
					<!--<el-table-column prop="commentTime" label="时间"></el-table-column>-->
					<el-table-column label="操作" width="160px">
						<template slot-scope="scope">
							<!--<el-button @click="openRaceComment(scope.row)" type="text" size="small">修 改</el-button>-->
							<el-popconfirm title="是否删除？" @confirm="delRaceComment(scope.row.commentId)">
								<el-button slot="reference" type="text" size="small">删 除</el-button>
							</el-popconfirm>
						</template>
					</el-table-column>
				</el-table>
			</el-col>
		</el-row>
		<!--弹框-->
		<el-dialog :title="racePostForm.ttitle" :visible.sync="racePostForm.visible" width="30%">
			<el-form :model="racePostForm" :rules="racePostRules" ref="racePostForm" label-width="100px">
				<!-- -->
				<el-form-item label="发布人" prop="postUserId">
					<el-input v-model="racePostForm.postUserId"></el-input>
				</el-form-item>
				<el-form-item label="内容" prop="postText">
					<el-input v-model="racePostForm.postText"></el-input>
				</el-form-item>
				<el-form-item label="发布时间" prop="postTime">
					<el-input v-model="racePostForm.postTime"></el-input>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="closeRacePost">取 消</el-button>
				<el-button type="primary" @click="saveRacePost">保 存</el-button>
			</span>
		</el-dialog>
	</div>
</body>
<script type="text/javascript" layout:fragment="fragment_script">
	let vueData = {
		racePosts: [],
		raceComments: [],
		selectRacePost: null,
		racePostForm: {
			visible: false,
			ttitle: '新增/修改',
			postId : '',
			postUserId : '',
			postText : '',
			postTime : '',
		},
		racePostQuery: {
			userId: 'not',
			page: '',
			size: '',
		},
		racePostRules: {
			postId: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			postUserId: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			postText: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			postTime: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
		},
	}
	let vueMethods = {
		getRacePosts() {
			let that = this
			postRequst('/getPosts', that.racePostQuery, true).then(function (resp) {
				that.racePosts = resp.rows
				if (resp.rows && resp.rows.length > 0) {
					that.selectRacePost = resp.rows[0]
					that.getRaceComments()
				}
			})
		},
		getRaceComments() {
			let that = this
			postRequst('/getComments', {postId:that.selectRacePost.postId,userId: 'not'}, true).then(function (resp) {
				that.raceComments = resp.rows
			})
		},
		viewRacePost(row){
			let that = this
			that.selectRacePost = row
			that.getRaceComments()
		},
		openRacePost(row) {
			let that = this
			if (row) {
				that.racePostForm.ttitle = '修改'
				that.racePostForm.postId = row.postId
				that.racePostForm.postUserId = row.postUserId
				that.racePostForm.postText = row.postText
				that.racePostForm.postTime = row.postTime
			} else {
				that.racePostForm.ttitle = '新增'
				that.racePostForm.postId = ''
				that.racePostForm.postUserId = ''
				that.racePostForm.postText = ''
				that.racePostForm.postTime = ''
			}
			that.racePostForm.visible = true
		},
		closeRacePost() {
			this.$refs["racePostForm"].resetFields();
			this.racePostForm.visible = false
		},
		saveRacePost() {
			let that = this
			this.$refs["racePostForm"].validate((valid) => {
				if (valid) {
					postRequst('/admin/saveRacePost', that.racePostForm).then(function (resp) {
						if (resp.status == 0) {
							that.getRacePosts()
							that.racePostForm.visible = false
							that.$message({message: resp.msg, type: "success"});
						} else {
							that.$message({message: resp.msg, type: "error"});
						}
					})
				}
			});
		},
		delRacePost(postId) {
			let that = this
			postRequst('/delPost', {postId: postId}, true).then(function (resp) {
				if (resp.status == 0) {
					that.getRacePosts()
					that.$message({message: resp.msg, type: "success"});
				} else {
					that.$message({message: resp.msg, type: "error"});
				}
			})
		},
		delRaceComment(commentId) {
			let that = this
			postRequst('/delComment', {commentId: commentId}, true).then(function (resp) {
				if (resp.status == 0) {
					that.getRaceComments()
					that.$message({message: resp.msg, type: "success"});
				} else {
					that.$message({message: resp.msg, type: "error"});
				}
			})
		},
	}
	function vueCreated() {
		let that = this
		that.getRacePosts()
	}
</script>

</html>